import request from '../utils/request';

/**
 * 创建升级策略
 * @param {string} description 升级策略描述
 * @param {number} packageId 升级包id
 * @param {number} settingId 设置id
 * @param {boolean} active 升级策略开关
 * @param {string[]} deviceUuidList 设备uuid列表
 */
export function createUpgradeStrategyApi(description, packageId, settingId, active, deviceUuidList) {
  return request({
    url: '/upgrade_strategies',
    method: 'post',
    data: {
      description: description,
      package_id: packageId,
      setting_id: settingId,
      active: active,
      device_uuid_list: deviceUuidList
    }
  });
}

/**
 * 删除升级策略
 * @param {string} uuid
 */
export function deleteUpgradeStrategyApi(uuid) {
  return request({
    url: '/upgrade_strategies/' + uuid,
    method: 'delete'
  });
}

/**
 *  更新升级策略
 * @param {string} uuid
 * @param {string} description
 * @param {number} packageId
 * @param {number} settingId
 * @param {boolean} active
 * @param {string[]} deviceUuidList
 */
export function updateUpgradeStrategyApi(uuid, description, packageId, settingId, active, deviceUuidList) {
  return request({
    url: '/upgrade_strategies/' + uuid,
    method: 'put',
    data: {
      description: description,
      package_id: packageId,
      setting_id: settingId,
      active: active,
      device_uuid_list: deviceUuidList
    }
  });
}

/**
 * 获取更新策略列表
 * @param {number} pageIndex 页码下标，默认从0开始
 * @param {number} pageSize 每页大小
 * @param {string} sortType 正序or倒序
 */
export function getUpgradeStrategyListApi(pageIndex, pageSize, sortType) {
  return request({
    url: '/upgrade_strategies',
    method: 'get',
    params: {
      page_index: pageIndex,
      page_size: pageSize,
      sort_type: sortType
    }
  });
}

/**
 * 获取更新策略参数接口
 * @param {string} uuid
 */
export function getUpgradeStrategyDetailApi(uuid) {
  return request({
    url: '/upgrade_strategies/' + uuid,
    method: 'get'
  });
}
